<%@ page language="java"
	import="java.util.*,com.wit.po.Company,com.wit.po.Subcompany,com.wit.po.Department,com.wit.service.impl.DLcompanyserviceImp"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
	DLcompanyserviceImp dlc = new DLcompanyserviceImp();
	List list = dlc.CompanyList();
	Company company = (Company) list.get(0);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>组织管理</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link href="<%=basePath%>/style/main.css" rel="stylesheet"
			type="text/css" />
		<link type="text/css" rel="stylesheet"
			href="<%=basePath%>/style/style.css" />
		<style>
body#bodyTree {
	margin: 8px;
	font-size: 12px;
	color: #000;
	line-height: 22px;
}

body#bodyTree a {
	color: #000;
	text-decoration: none;
}

body#bodyTree a:hover {
	color: #3366CC;
	padding: 2px 0px 0px 0px;
}

#bodyTree ul {
	margin: 0;
	padding: 0;
	list-style: none;
	background: url(<%=basePath%>/images/tree/ullist.gif) repeat-y;
}

#bodyTree ul li {
	list-style: none;
}

#bodyTree .treeview li {
	background: transparent url(<%=basePath%>/images/tree/list.gif)
		no-repeat left center;
	padding-left: 15px; /*tree list*/
}

#bodyTree .treeview li.submenu {
	background: transparent url(<%=basePath%>/images/tree/closed.gif)
		no-repeat left 0px; /*4 sub menu*/
}

#bodyTree .treeview li.closefolder {
	background: transparent url(<%=basePath%>/images/tree/closed.gif)
		no-repeat left 0px; /*closefolder style*/
}

#bodyTree .treeview li.openfolder {
	background: transparent url(<%=basePath%>/images/tree/open.gif)
		no-repeat left 0px;
	/*openfolder style*/
}

#bodyTree .treeview li.submenu ul {
	display: none;
}

#bodyTree ul li a.cur {
	font-weight: bold;
	color: #3366CC;
	padding: 2px 2px 0px 2px; /*the current style*/
}

#bodyTree .treeview .submenu i {
	width: 12px;
	height: 12px;
	font-style: normal;
	font-size: 10px;
	margin-left: -15px;
	margin-top: 5px;
	float: left;
	display: inline;
	background: url(<%=basePath%>/images/tree/transparent.gif) no-repeat
		center;
	cursor: pointer;
}

#cmsTree {
	float: left;
	width: 15%;
}

#rightDiv {
     border:1px solid #5BA8DE;
     width:70%;
}

#Containner {	
}
	.mydiv input {
		width: 160px;
		font-size: 15pt;
		border: solid 1px #7F9DB9;
		font-size: 15px;	
       }
	.mydiv{
	background-color: #F1F6FF;
	}
	.mydiv legend{
	font-size: 20px;	
	}
</style>
		<script type="text/javascript"
			src="<%=basePath%>/images/tree/simpletreemenu.js">
</script>
		<script type="text/javascript" src="<%=basePath%>/js/jquery-1.3.1.js">
</script>
		<script type="text/javascript">
		function GetMessage(subId)
		{
	       document.getElementById("CompanyDiv").style.display="none";
		   document.getElementById("DepartmentDiv").style.display="none";
		   document.getElementById("subCompanyDiv").style.display="";
		  
		 var parameter = {
		subcommpanyId : subId
	}; 
	$.ajax( {
		type : "post",
		dataType : "json",
		data : parameter,
		url : "ReturnSuCompany", 
		success:function(data){
		$("#smemo").val(data.smemo);
		$("#scommrate").val(data.scommrate);
		$("#spound").val(data.spound);
		$("#semail").val(data.semail);
		$("#sfax").val(data.sfax);
		$("#stelephone").val(data.stelephone);
		$("#spostcode").val(data.spostcode);
		$("#schief").val(data.employeeName);
		$("#saddress").val(data.saddress);
		$("#sfullName").val(data.sfullName);
		$("#sshortName").val(data.sshortName);
		$("#subcommpanyId").val(data.subcommpanyId);
		}
		});
		}
	
		$(document).ready(function(){
		$("#newCompany").click(function(){
		var companyid=$("#subcommpanyId").val();
		window.location.href("<%=basePath%>/Personnel/newSubcompanyDL.jsp?companyId="+companyid);		
		});
        $("#newDepartment").click(function(){
        var companynum=$("#companyNum").val();
        window.location.href("<%=basePath%>/Personnel/newComDepartment.jsp?companyNum="+companynum);
        });
        $("#newSSDep").click(function(){
        var subcompanyNum=$("#subcommpanyId").val();
		window.location.href("<%=basePath%>/Personnel/newSubComDepartment.jsp?subcompanyNum="+subcompanyNum);	
        });
        $("#DelSubCompany").click(function(){
         var subcompanyNum=$("#subcommpanyId").val();
         window.location.href("DelSubcompany?subcommpanyId="+subcompanyNum);	

        });
        
          $("#DelDepartment").click(function(){
         var departmentId=$("#departmentId").val();
         window.location.href("DeleteDepartmentAction?departmentId="+departmentId);	

        });
        
          $("#newfuck").click(function(){
         var companynum=$("#companyNum").val();
         window.location.href("<%=basePath%>/Personnel/newSubcompany.jsp");	

        });
		})
		
function GetTree(num) {
           document.getElementById("subCompanyDiv").style.display="none";
           document.getElementById("DepartmentDiv").style.display="none";
		   document.getElementById("CompanyDiv").style.display="";
	var param = {
		comNum : num
	};
	$.ajax( {
		type : "post",
		dataType : "json",
		data : param,
		url : "ReturnCompany",
		success : function(data) {
		$("#companynameE").val(data.companynameE);
		$("#companyNum").val(data.companyNum);
		$("#shortName").val(data.shortName);
		$("#companynameC").val(data.companynameC);
		$("#cmemo").val(data.cmemo);
		$("#companyAddress").val(data.companyAddress);
		$("#ctelephone").val(data.ctelephone);
		$("#cpostCode").val(data.cpostCode);
		$("#cfax").val(data.cfax);
		$("#cemail").val(data.cemail);
		$("#webAddress").val(data.webAddress);
		$("#cbankName").val(data.cbankName);
		$("#bankAccount").val(data.bankAccount);
		$("#cintroduct").val(data.cintroduct);
	}
	});
	}
	function dep2(num)
	{
	   document.getElementById("subCompanyDiv").style.display="none";
	   document.getElementById("CompanyDiv").style.display="none";
       document.getElementById("DepartmentDiv").style.display="";
	   var param = {
		departmentId : num
	};
	$.ajax( {
		type : "post",
		dataType : "json",
		data : param,
		url : "ReturnDepartment",
		success : function(data) {
		$("#departmentId").val(data.departmentId);
		$("#departNameC").val(data.departNameC);
		$("#departNameE").val(data.departNameE);
		$("#dposeCode").val(data.dposeCode);
		$("#daddress").val(data.daddress);
		$("#dphone").val(data.dphone);
		$("#dfax").val(data.dfax);
		$("#demail").val(data.demail);
		$("#dcrMan").val(data.dcrMan);
		$("#shortName").val(data.shortName);
		$("#dcdate").val(data.dcdate);
		
	}
	});
	 }
	 
</script>
	</head>
		<body id="bodyTree">
			<div id="Containner">
				<div id="cmsTree">
				
					<ul id="treemenu3" class="treeview">
						<li>
							<strong>组织架构</strong>
							<a href="javascript:ddtreemenu.flatten('treemenu3', 'expand')"><strong>展开</strong>
							</a>
							<a href="javascript:ddtreemenu.flatten('treemenu3', 'contact')"><strong>收缩</strong>
							</a>
						</li>
						<li>
							<i></i><span onclick="GetTree('<%=company.getCompanyNum()%>')"><%=company.getCompanynameC()%></span>
							<%
							    List<Department> dlist=dlc.ReturncompanyD(company.getCompanyNum()); 
							    if(dlist.size()>0)
							    {
							%>
							<ul>
							        <%
							        for(int i=0;i<dlist.size();i++)
							        { 
							        %>
							        <li><span onclick="dep2('<%=dlist.get(i).getDepartmentId()%>')"><%=dlist.get(i).getDepartNameC() %></span></li>
							        <%
							        }
							        %>
							
							<%
							   }
							 %>
							<%
								List<Subcompany> flist = dlc.FirstLevel();
								if (flist.size() > 0) {
							%>
							<ul>
								<%
									for (int i = 0; i < flist.size(); i++) {
											//第一层代理
											Subcompany sub = flist.get(i);
								%>

								<li>
									<i></i><span onclick="GetMessage('<%=sub.getSubcommpanyId()%>')"><%=sub.getSshortName()%></span>
									<%
									   List<Department> alist=dlc.ReturnSubcompanyD(sub.getSubcommpanyId()); 
							           if(alist.size()>0)
							          {
									%>
									   <ul>
									    <%
									    for(int j=0;j<alist.size();j++)
									    {
									    %>
									    <li><span onclick="dep2('<%=alist.get(j).getDepartmentId() %>')"><%=alist.get(j).getDepartNameC() %></span></li>
									    <%
									    } 
									    %>
									   </ul>
									<% 
									   }
									%>
									<%
										int size = sub.getSubcompanies().size();
												if (size > 0) {
													//第二层
									%>
									<ul>
										<%
											Iterator it = sub.getSubcompanies().iterator();
														while (it.hasNext()) {
															Subcompany selevel = (Subcompany) it.next();
										%>

										<li>
											<i></i><span onclick="GetMessage('<%=selevel.getSubcommpanyId()%>')"><%=selevel.getSshortName()%></span>
											<%
										  	 List<Department> blist=dlc.ReturnSubcompanyD(selevel.getSubcommpanyId()); 
								          	 if(blist.size()>0)
								          	{
										   %>
										   <ul>
										    <%
										    for(int k=0;k<blist.size();k++)
										    {
										    %>
										    <li><span onclick="dep2('<%=blist.get(k).getDepartmentId() %>')"><%=blist.get(k).getDepartNameC() %></span></li>
										    <%
										    } 
										    %>
										   </ul>
											<% 
										  	 }
											%>
											<%
												int three = selevel.getSubcompanies().size();
																if (three > 0) {
																	//第三层
											%>
											<ul>
												<%
													Iterator threeit = selevel.getSubcompanies()
																				.iterator();
																		while (threeit.hasNext()) {
																			Subcompany threelevelc = (Subcompany) threeit
																					.next();
												%>

												<li>
													<i></i><span onclick="GetMessage('<%=threelevelc.getSubcommpanyId()%>')"><%=threelevelc.getSshortName()%></span>
													<%
												  	 List<Department> clist=dlc.ReturnSubcompanyD(threelevelc.getSubcommpanyId()); 
										          	 if(clist.size()>0)
										          	{
												   %>
												   <ul>
												    <%
												    for(int k=0;k<clist.size();k++)
												    {
												    %>
												    <li><span onclick="dep2('<%=clist.get(k).getDepartmentId() %>')"><%=clist.get(k).getDepartNameC() %></span></li>
												    <%
												    } 
												    %>
												   </ul>
													<% 
												  	 }
													%>
													<%
														int four = threelevelc.getSubcompanies()
																						.size();
																				if (four > 0) {
																					//第四层
													%>
													<ul>
														<%
															Iterator fourlevel = threelevelc
																								.getSubcompanies().iterator();
																						while (fourlevel.hasNext()) {
																							Subcompany fourlevelc = (Subcompany) fourlevel
																									.next();
														%>

														<li>
															<i></i><span onclick="GetMessage('<%=fourlevelc.getSubcommpanyId()%>')"><%=fourlevelc
													.getSshortName()%></span>
													<%
												  	 List<Department> elist=dlc.ReturnSubcompanyD(fourlevelc.getSubcommpanyId()); 
										          	 if(elist.size()>0)
										          	{
												   %>
												   <ul>
												    <%
												    for(int k=0;k<elist.size();k++)
												    {
												    %>
												    <li><span onclick="dep2('<%=elist.get(k).getDepartmentId() %>')"><%=elist.get(k).getDepartNameC() %></span></li>
												    <%
												    } 
												    %>
												   </ul>
													<% 
												  	 }
													%>
															<%
																int five = fourlevelc
																										.getSubcompanies().size();
																								if (five > 0) {
															%>
															<ul>
																<%
																	Iterator fivelevel = fourlevelc
																												.getSubcompanies()
																												.iterator();

																										while (fivelevel.hasNext()) {
																											Subcompany fivelevelc = (Subcompany) fivelevel
																													.next();
																%>
																<li><span onclick="GetMessage('<%=fivelevelc.getSubcommpanyId()%>')"><%=fivelevelc
															.getSshortName()%></span>
															<%
												  	 List<Department> klist=dlc.ReturnSubcompanyD(fivelevelc.getSubcommpanyId()); 
										          	 if(klist.size()>0)
										          	{
												   %>
												   <ul>
												    <%
												    for(int k=0;k<klist.size();k++)
												    {
												    %>
												    <li><span onclick="dep2('<%=klist.get(k).getDepartmentId() %>')"><%=klist.get(k).getDepartNameC() %></span></li>
												    <%
												    } 
												    %>
												   </ul>
													<% 
												  	 }
													%>
															</li>
																<%
																	}
																%>
															</ul>
															<%
																}
															%>
														</li>
												</li>
												<%
													}
												%>
											</ul>
											<%
												}
											%>
										</li>
										<%
											}
										%>
									</ul>
									<%
										}
									%>
								</li>
								<%
									}
								%>
							</ul>
							<%
								}
							%>
						</li>
						<%
							//到这里第一层结束
								}
						%>
					</ul>
					</ul>
					<%
						}
					%>
					
					
				</div>
				
				<div id="rightDiv" style="position:absolute">
				
                   <div class="mydiv" id="CompanyDiv">
                   <div class="fuckyouDiv">
                   <p>
                   <span class="clientinfo_but" id="newfuck">新增公司</span> <span class="clientinfo_but" id="newDepartment" >新增部门</span>
                   </p>
                 </div>
                   <p>&nbsp;</p>
    <form id="CompanyForm" action="MendCompanyAction" method="post">
    <fieldset> 
   <div class="FuckTittle"><span class="title">基本资料</span></div>
      <p>&nbsp;</p>
      <div class="table4">
    <p>
    <label for="companyNum">公司编号：</label><input type="text" name="companyNum" id="companyNum" readonly="readonly"/>&nbsp;&nbsp;&nbsp;&nbsp;
    公司简称：<input type="text" id="shortName" name="shortName"/>
    </p><p>&nbsp;</p>
    <p>
     <label for="companynameC">中文名称：</label><input type="text" name="companynameC" id="companynameC"/>&nbsp;&nbsp;&nbsp;&nbsp;
     英文名称：<input type="text" id="companynameE" name="companynameE"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="companyAddress">公司地址：</label><input type="text" name="companyAddress" id="companyAddress"/>&nbsp;&nbsp;&nbsp;&nbsp;
     公司电话：<input type="text" id="ctelephone" name="ctelephone"/>
    </p><p>&nbsp;</p>
    <p>
     <label for="cpostCode">公司邮编：</label><input type="text" name="cpostCode" id="cpostCode"/>&nbsp;&nbsp;&nbsp;&nbsp;
     公司传真：<input type="text" id="cfax" name="cfax"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="cemail">公司邮箱：</label><input type="text" name="cemail" id="cemail"/>&nbsp;&nbsp;&nbsp;&nbsp;
     公司主页：<input type="text" id="webAddress" name="webAddress"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="cbankName">开户银行名称：</label><input type="text" name="cbankName" id="cbankName"/>&nbsp;&nbsp;&nbsp;&nbsp;
银行账户：<input type="text" id="bankAccount" name="bankAccount"/>
    </p><p>&nbsp;</p>
     <p>
     公司简介：<textarea rows="5" cols="30" id="cintroduct" name="cintroduct"></textarea>&nbsp;&nbsp;&nbsp;&nbsp;
     公司备注：<textarea rows="5" cols="30" id="cmemo" name="cmemo"></textarea>
    </p><p>&nbsp;</p>
    <p >
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="input" type="submit"  value="修改"  class="btn_1" />&nbsp;&nbsp; <input name="input" type="reset"  value="取消"  class="btn_1" onclick="test2()"/>
    </p>
    </div>
    </fieldset>
   </form>
   </div>  
   <div id="subCompanyDiv" class="mydiv" style="display:none">
     <div class="fuckyouDiv">
     <p>
         <span class="clientinfo_but" id="newCompany">新增公司</span>   <span class="clientinfo_but" id="DelSubCompany">删除公司</span> <span class="clientinfo_but" id="newSSDep">新增部门</span>
     </p>
     </div>
     <p>&nbsp;</p>
    <form id="SubCompanyMessage" action="MendSubcomMessage" method="post">
    <fieldset> 
    <div class="FuckTittle"><span class="title">基本资料</span></div>
      <p>&nbsp;</p>
      <div class="table4">
    <p>
    <label for="subcommpanyId">公司编号：</label><input type="text" name="subcommpanyId" id="subcommpanyId" readonly="readonly"/>&nbsp;&nbsp;&nbsp;&nbsp;
    公司简称:<input type="text" id="sshortName" name="sshortName"/>
    </p><p>&nbsp;</p>
    <p>
     <label for="sfullName">公司全称：</label><input type="text" name="sfullName" id="sfullName"/>&nbsp;&nbsp;&nbsp;&nbsp;
     公司地址:<input type="text" id="saddress" name="saddress"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="schief">公司负责人：</label><input type="text" name="schief" id="schief"/>&nbsp;&nbsp;&nbsp;&nbsp;
     公司电话:<input type="text" id="stelephone" name="stelephone"/>
    </p><p>&nbsp;</p>
    <p>
     <label for="spostcode">公司邮编：</label><input type="text" name="spostcode" id="spostcode"/>&nbsp;&nbsp;&nbsp;&nbsp;
     公司传真：<input type="text" id="sfax" name="sfax"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="semail">公司邮箱：</label><input type="text" name="semail" id="semail"/>&nbsp;&nbsp;&nbsp;&nbsp;
     手续费率：<input type="text" id="spound" name="spound"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="scommrate">佣金比率：</label><input type="text" name="scommrate" id="scommrate"/>&nbsp;&nbsp;&nbsp;&nbsp;

    </p><p>&nbsp;</p>
     <p>
     公司备注：<textarea rows="5" cols="30" id="smemo" name="smemo"></textarea>&nbsp;&nbsp;&nbsp;&nbsp;
    </p><p>&nbsp;</p>
    <p >
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="input" type="submit"  value="修改"  class="btn_1" />&nbsp;&nbsp; <input name="input" type="reset"  value="取消"  class="btn_1" onclick="test2()"/>
    </p>
    </div>
    </fieldset>
   </form>
   </div>  
   
   <div id="DepartmentDiv" class="mydiv" style="display:none">
    <div class="fuckyouDiv">
     
    <p>
         <span class="clientinfo_but"  id="DelDepartment">删除部门</span>   
     </p></div>
     <p>&nbsp;</p>
    <form id="SubCompanyMessage" action="MendSDepatemtmentAction" method="post">
    <fieldset> 
    <div class="FuckTittle"><span class="title">部门基本资料</span></div>
      <p>&nbsp;</p>
      <div class="table4">
    <p>
    <label for="departmentId">部门编号：</label><input type="text" name="departmentId" id="departmentId" readonly="readonly"/>&nbsp;&nbsp;&nbsp;&nbsp;
    部门简称：<input type="text" id="shortName" name="shortName"/>
    </p><p>&nbsp;</p>
    <p>
     <label for="departNameC">中文名称：</label><input type="text" name="departNameC" id="departNameC"/>&nbsp;&nbsp;&nbsp;&nbsp;
     英文名称：<input type="text" id="departNameE" name="departNameE"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="daddress">详细地址：</label><input type="text" name="daddress" id="daddress"/>&nbsp;&nbsp;&nbsp;&nbsp;
     邮&nbsp;&nbsp;&nbsp;&nbsp;编：<input type="text" id="dposeCode" name="dposeCode"/>
    </p><p>&nbsp;</p>
    <p>
     <label for="demail">部门邮箱：</label><input type="text" name="demail" id="demail"/>&nbsp;&nbsp;&nbsp;&nbsp;
     部门电话：<input type="text" id="dphone" name="dphone"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="dcrMan">负责&nbsp;&nbsp;人：</label><input type="text" name="dcrMan" id="dcrMan"/>&nbsp;&nbsp;&nbsp;&nbsp;
     创建时间：<input  type="text" id="dcdate" name="dcdate"/>
    </p><p>&nbsp;</p>
     <p>
     <label for="dfax">部门传真：</label><input type="text" name="dfax" id="dfax"/>&nbsp;&nbsp;&nbsp;&nbsp;
    </p><p>&nbsp;</p>
    <p >
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="input" type="submit"  value="修改"  class="btn_1" />&nbsp;&nbsp; <input name="input" type="reset"  value="取消"  class="btn_1" onclick="test2()"/>
    </p>
    </div>
    </fieldset>
   </form>
   </div>   				
				</div>
			</div>
			<script type="text/javascript">
              ddtreemenu.createTree("treemenu3", true);
            </script>

		</body>
</html>
